package com.hzit.controller;

import com.hzit.dto.StudentDTO;
import com.hzit.entity.Student;
import com.hzit.service.IStudentService;
import com.hzit.util.PageResult;
import com.hzit.util.R;
import com.hzit.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
	@Autowired
	private IStudentService studentService;

	//1. 列表学生
	@GetMapping("/list")
	public R list(){
		List<Student> students = studentService.list();
		return R.ok(students);
	}
	//2. 分页查询 http://localhost:9000/1/5
	@GetMapping("/findByPage/{page}/{pageSize}")
	public R findBypage(@PathVariable Integer page,@PathVariable("pageSize") Integer pageSize){
		PageResult<StudentDTO> dtos = studentService.findByPage(page,pageSize);
		return R.ok(dtos);
	}
	//3. 条件查询带分页
	@PostMapping("/search/{page}/{pageSize}")
	public R search(@PathVariable Integer page,
	                @PathVariable("pageSize") Integer pageSize,
	                @RequestBody StudentVo vo){
		PageResult<StudentDTO> dtos = studentService.search(page,pageSize,vo);
		return R.ok(dtos);
	}
}
